#!/usr/bin/env python3
"""获取数据预处理统计信息"""

import json
from pathlib import Path

train_file = Path('data/processed/segmentation/train_split.json')
val_file = Path('data/processed/segmentation/val_split.json')
test_file = Path('data/processed/segmentation/test_split.json')
results_file = Path('data/processed/segmentation/preprocessing_results.json')

# 加载数据
train = json.load(open(train_file))
val = json.load(open(val_file))
test = json.load(open(test_file))
results = json.load(open(results_file))

# 统计
all_samples = train['samples'] + val['samples'] + test['samples']
echonet = [s for s in all_samples if s.get('type') == 'echonet_dynamic']
cardiacnet = [s for s in all_samples if s.get('type') == 'cardiacnet']

train_echonet = len([s for s in train['samples'] if s.get('type') == 'echonet_dynamic'])
train_cardiacnet = len([s for s in train['samples'] if s.get('type') == 'cardiacnet'])
val_echonet = len([s for s in val['samples'] if s.get('type') == 'echonet_dynamic'])
val_cardiacnet = len([s for s in val['samples'] if s.get('type') == 'cardiacnet'])
test_echonet = len([s for s in test['samples'] if s.get('type') == 'echonet_dynamic'])
test_cardiacnet = len([s for s in test['samples'] if s.get('type') == 'cardiacnet'])

print("="*60)
print("数据预处理统计")
print("="*60)
print()
print("预处理结果:")
echonet_result = results.get('echonet_dynamic', {})
cardiacnet_result = results.get('cardiacnet', {})
print(f"  EchoNet-Dynamic: {echonet_result.get('valid_samples', 0)}/{echonet_result.get('total_samples', 0)} 个样本")
print(f"  CardiacNet: {cardiacnet_result.get('valid_samples', 0)}/{cardiacnet_result.get('total_samples', 0)} 个样本")
print()
print("数据划分:")
print(f"  训练集: {len(train['samples'])} 个样本")
print(f"    - EchoNet-Dynamic: {train_echonet} 个")
print(f"    - CardiacNet: {train_cardiacnet} 个")
print()
print(f"  验证集: {len(val['samples'])} 个样本")
print(f"    - EchoNet-Dynamic: {val_echonet} 个")
print(f"    - CardiacNet: {val_cardiacnet} 个")
print()
print(f"  测试集: {len(test['samples'])} 个样本")
print(f"    - EchoNet-Dynamic: {test_echonet} 个")
print(f"    - CardiacNet: {test_cardiacnet} 个")
print()
print(f"总计: {len(all_samples)} 个样本")
print(f"  - EchoNet-Dynamic: {len(echonet)} 个")
print(f"  - CardiacNet: {len(cardiacnet)} 个")
print("="*60)

